package com.itheima.app.controller.pmsController;

import com.itheima.app.manager.pmsManager.PmsProductManager;
import com.itheima.app.manager.pmsManager.ProductAttributeCategoryManager;
import com.itheima.commons.R;
import com.itheima.domain.db.pms.PmsProductAttributeCategory;
import com.itheima.domain.db.pms.PmsProductCategory;
import com.itheima.vo.pms.PmsProductCategoryVo;
import com.itheima.vo.pms.ProductAttributeCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProductAttributeCategoryController {


    @Autowired
    ProductAttributeCategoryManager productAttributeCategoryManager;

    //添加商品分类
    @PostMapping("/productCategory/create")
    public R addProductCategory(@RequestBody PmsProductCategoryVo pmsProductCategoryVo) {

        return productAttributeCategoryManager.addProductCategory(pmsProductCategoryVo);
    }

    //添加商品属性分类
    @PostMapping("/productAttribute/category/create")
    public R addProductAttribute(@RequestBody PmsProductAttributeCategory productAttributeCategory) {
        return productAttributeCategoryManager.add(productAttributeCategory);
    }

    //删除单个商品属性分类
    @GetMapping("/productAttribute/category/delete/{id}")
    public R deleteById(@PathVariable Integer id) {
        return productAttributeCategoryManager.delete(id);
    }


    //分页获取所有商品属性分类
    @GetMapping("/productAttribute/category/list")
    public R getPageList(Integer pageNum, Integer pageSize) {

        return productAttributeCategoryManager.getPageList(pageNum, pageSize);
    }


    //获取所有商品属性分类及其下属性
    @GetMapping("/productAttribute/category/list/withAttr")
    public R categoryListWithAttr() {
        List<ProductAttributeCategoryVo> list = productAttributeCategoryManager.categoryListWithAttr();
        return R.ok(list);
    }

    //修改商品属性分类
    @PostMapping("/productAttribute/category/update/{id}")
    public R updateProduct(@RequestBody PmsProductCategory productCategory, @PathVariable("id") Integer id) {
        productAttributeCategoryManager.updateProduct(productCategory, id);
        return R.ok(null);
    }

    //获取单个商品属性分类信息
    @GetMapping("/productAttribute/category/{id}")
    public R getProduct(@PathVariable("id") Integer id) {
        PmsProductCategory productCategory = productAttributeCategoryManager.getProduct(id);
        return R.ok(productCategory.getName());
    }

}
